// pages/fond/search.js

var config = require('../../config')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    books: [],
    name: '',
    modalHidden: true,
  },

  bindViewTap: function (e) {
    // this.setData({
    //   modalHidden: !this.data.modalHidden
    // })
    var name = e.target.id;
    var books = new Array();
    var contectway = "";
    var contect = "";
    books = this.data.books;
    for (var i = 0; i < books.length; i++) {
      if (name == books[i].buyername) {
        contectway = books[i].contectId;
        contect = books[i].contect;
      }
    }
    wx.showModal({
      title: '联系方式',
      content: contectway + ":" + contect,
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定')
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })  

  },

  modalBindaconfirm: function () {
    this.setData({
      modalHidden: !this.data.modalHidden,
    })
  },

  modalBindcancel: function () {
    this.setData({
      modalHidden: !this.data.modalHidden,
    })
  },

  searchBooks: function (e) {
    var name = e.detail.value;
		var _this = this;
		wx.request({
			url: `${config.service.host}/weapp/SearchBook`,
			data: {
				type: 2,
				name: name
			},
			method: "GET",
			header: {
				"Content-Type": "application/json"
			},
			success: function (e) {
				_this.setData({ books: e.data })
			}
		})

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})